package com.iq50.client.routeguide;

import com.iq50.client.grpc.SimpleGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class RouteGuideClient {

    @Value("${gRPC.host}")
    private static String host;
    @Value("${gRPC.port}")
    private static int port;
    private final ManagedChannel channel;
    private final RouteGuideGrpc.RouteGuideBlockingStub blockingStub;

    private final RouteGuideGrpc.RouteGuideStub asyncStub;

    public RouteGuideClient(){
        this(ManagedChannelBuilder.forAddress("127.0.0.1", 50051).usePlaintext());
    }

    private RouteGuideClient(ManagedChannelBuilder<?> channelBuilder) {
        this.channel = channelBuilder.build();
        this.blockingStub = RouteGuideGrpc.newBlockingStub(channel);
        this.asyncStub = RouteGuideGrpc.newStub(channel);
    }

    public RouteGuideGrpc.RouteGuideBlockingStub getRPCMethods(){
        return this.blockingStub;
    }

    public RouteGuideGrpc.RouteGuideStub getRPCAsyncMethods(){
        return this.asyncStub;
    }

}
